package com.cjkj.consumables.controller;

import com.cjkj.common.annotation.Log;
import com.cjkj.common.annotation.RepeatSubmit;
import com.cjkj.common.core.controller.BaseController;
import com.cjkj.common.core.domain.AjaxResult;
import com.cjkj.common.core.page.TableDataInfo;
import com.cjkj.common.enums.BusinessType;
import com.cjkj.common.utils.poi.ExcelUtil;
import com.cjkj.consumables.domain.TMedicalConsumablesInfo;
import com.cjkj.consumables.domain.dto.BatchOperateParam;
import com.cjkj.consumables.domain.dto.ConsumablesDistributionReq;
import com.cjkj.consumables.domain.dto.ListDataParam;
import com.cjkj.consumables.service.ITMedicalConsumablesInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 耗材信息Controller
 * 
 * @author cjkj
 * @date 2025-10-11
 */
@RestController
@RequestMapping("/consumables/info")
public class TMedicalConsumablesInfoController extends BaseController
{
    @Resource
    private ITMedicalConsumablesInfoService tMedicalConsumablesInfoService;

    /**
     * 查询耗材信息列表
     */
    @PreAuthorize("@ss.hasPermi('consumables:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(ListDataParam param)
    {
        startPage();
        List<TMedicalConsumablesInfo> list = tMedicalConsumablesInfoService.selectTMedicalConsumablesInfoList(param);
        return getDataTable(list);
    }

    /**
     * 导出耗材信息列表
     */
    @PreAuthorize("@ss.hasPermi('consumables:info:export')")
    @Log(title = "耗材信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ListDataParam param)
    {
        List<TMedicalConsumablesInfo> list = tMedicalConsumablesInfoService.selectTMedicalConsumablesInfoList(param);
        ExcelUtil<TMedicalConsumablesInfo> util = new ExcelUtil<TMedicalConsumablesInfo>(TMedicalConsumablesInfo.class);
        util.exportExcel(response, list, "耗材信息数据");
    }

    /**
     * 新增耗材信息
     */
    @PreAuthorize("@ss.hasPermi('consumables:info:add')")
    @Log(title = "耗材信息", businessType = BusinessType.INSERT)
    @RepeatSubmit(interval = 1000, message = "请求过于频繁！")
    @PostMapping
    public AjaxResult add(@RequestBody @Valid TMedicalConsumablesInfo tMedicalConsumablesInfo)
    {
        return toAjax(tMedicalConsumablesInfoService.insertTMedicalConsumablesInfo(tMedicalConsumablesInfo));
    }

    /**
     * 通过号段批量新增耗材信息
     */
    @PreAuthorize("@ss.hasPermi('consumables:info:add')")
    @Log(title = "耗材信息批量新增", businessType = BusinessType.INSERT)
    @RepeatSubmit(interval = 1000, message = "请求过于频繁！")
    @PostMapping("batchAdd")
    public synchronized AjaxResult batchAdd(@RequestBody @Valid BatchOperateParam param)
    {
        return AjaxResult.success(tMedicalConsumablesInfoService.batchAddInfo(param));
    }

    /**
     * 删除耗材信息
     */
    @PreAuthorize("@ss.hasPermi('consumables:info:remove')")
    @Log(title = "耗材信息", businessType = BusinessType.DELETE)
    @RepeatSubmit(interval = 1000, message = "请求过于频繁！")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tMedicalConsumablesInfoService.deleteTMedicalConsumablesInfoByIds(ids));
    }

    /**
     * 分配耗材
     */
    @Log(title = "耗材信息", businessType = BusinessType.DISTRIBUTION)
    @PreAuthorize("@ss.hasPermi('consumables:info:distribution')")
    @RepeatSubmit(interval = 1000, message = "请求过于频繁！")
    @PostMapping("/distribution")
    public AjaxResult distribution(@RequestBody @Valid ConsumablesDistributionReq req){
        return toAjax(tMedicalConsumablesInfoService.doDistribution(req));
    }

    /**
     * 回收耗材
     */
    @Log(title = "耗材信息", businessType = BusinessType.RECOVERY)
    @PreAuthorize("@ss.hasPermi('consumables:info:recovery')")
    @RepeatSubmit(interval = 1000, message = "请求过于频繁！")
    @PutMapping("/recovery/{ids}")
    public AjaxResult recovery(@PathVariable String[] ids)
    {
        return toAjax(tMedicalConsumablesInfoService.doRecovery(ids));
    }

    /**
     * 通过号段批量分配耗材
     */
    @PreAuthorize("@ss.hasPermi('consumables:info:distribution')")
    @Log(title = "耗材批量分配", businessType = BusinessType.DISTRIBUTION)
    @RepeatSubmit(interval = 1000, message = "请求过于频繁！")
    @PostMapping("batchDistribution")
    public synchronized AjaxResult batchDistribution(@RequestBody @Valid BatchOperateParam param)
    {
        return AjaxResult.success(tMedicalConsumablesInfoService.batchDistribution(param));
    }

    /**
     * 通过号段批量回收耗材
     */
    @PreAuthorize("@ss.hasPermi('consumables:info:recovery')")
    @Log(title = "耗材批量回收", businessType = BusinessType.RECOVERY)
    @RepeatSubmit(interval = 1000, message = "请求过于频繁！")
    @PostMapping("batchRecovery")
    public synchronized AjaxResult batchRecovery(@RequestBody @Valid BatchOperateParam param)
    {
        return AjaxResult.success(tMedicalConsumablesInfoService.batchRecovery(param));
    }
}
